//
//  MainShopCell.m
//  Ufan
//
//  Created by yangqingluo on 15/11/12.
//  Copyright © 2015年 yangqingluo. All rights reserved.
//

#import "MainProductCell.h"
#import "UIImageView+EMWebCache.h"

@interface MainProductCell(){
    
}

@property (nonatomic, strong) UIImageView *mainImageView;
@property (nonatomic, strong) UIImageView *tmImageView;
@property (nonatomic, strong) UIButton *detailButton;
@property (strong, nonatomic) UIView *bottomLineView1;

@end

@implementation MainProductCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.textLabel.backgroundColor = [UIColor clearColor];
        self.textLabel.textColor = [UIColor blackColor];
        self.textLabel.font = [UIFont systemFontOfSize:16.0];
        self.textLabel.numberOfLines = 3;
        
        
        _bottomLineView1 = [[UIView alloc] init];
        _bottomLineView1.backgroundColor = UFCOLOR_GRAYLINE;
        [self.contentView addSubview:_bottomLineView1];
    }
    return self;
}



-(void)layoutSubviews{
    [super layoutSubviews];
    
    _bottomLineView1.frame = CGRectMake(15, self.height - 1, self.width - 30, 1);
    
    NSURL *imageUrl = [NSURL URLWithString:self.product.mainUrl];
    [self.mainImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@""]];
    

    self.textLabel.text = self.product.name;
    self.textLabel.frame = CGRectMake(self.mainImageView.right + 10, self.mainImageView.top, _bottomLineView1.right - 10 - self.mainImageView.right, 80);
    

}


+(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}

- (void)buttonClick:(UIButton *)button{
    
    
}


#pragma getter

- (UIImageView *)mainImageView{
    if (!_mainImageView) {
        _mainImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 10, (self.height - 20) * 4.0 / 3.0, self.height - 20)];
        [self.contentView addSubview:_mainImageView];
    }
    
    return _mainImageView;
}

- (UIImageView *)tmImageView{
    if (!_tmImageView) {
        _tmImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
        _tmImageView.layer.cornerRadius = 0.5 * _tmImageView.width;
        _tmImageView.layer.masksToBounds = YES;
        _tmImageView.center = CGPointMake(0.5 * _tmImageView.bounds.size.width, self.bounds.size.height - 0.5 * _tmImageView.bounds.size.height);
        [self.contentView addSubview:_tmImageView];
    }
    
    return _tmImageView;
}

- (UIButton *)detailButton{
    if (!_detailButton) {
        _detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _detailButton.frame = CGRectMake(self.width - 110, self.height - 35, 100, 30);
        _detailButton.layer.cornerRadius = 5;
        _detailButton.layer.masksToBounds = YES;
        [_detailButton setBackgroundColor:[UIColor orangeColor]];
        [_detailButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _detailButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
        [_detailButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_detailButton];
    }
    
    return _detailButton;
}

@end
